package com.qq.weixin.util;

import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;
import java.util.Scanner;

import org.apache.http.Consts;

public class Constants {
	public static final Charset UTF_8 = Consts.UTF_8;
	public static final String COLOR_BLUE = color2String(Color.blue);
	public static final String COLOR_ORANGE = color2String(Color.ORANGE);
	public static final String TOKEN_STORE_PATH = "D:/tmp/token.txt";
	public static final String TEMPLATE_ID = "_nkNich2gLnlnqIrpkDb-JRYbUyUVuqt0Zz481qmbqI";
	public static String ACCESS_TOKEN = readToken();

	// tmp
	public static final String MY_OPENID = "oQeHTv2Pfmt7NcEnvwpRQYjBojMY";
	public static final String IMG_ID = "APpmBKKArjrj9mpUGfPQ9EkQBpWlBRQKsps1OvgvsALXS0o_F8oUxx5nBcv1EaCe";

	protected static String color2String(Color color) {
		String R = Integer.toHexString(color.getRed());
		R = R.length() < 2 ? ('0' + R) : R;
		String B = Integer.toHexString(color.getBlue());
		B = B.length() < 2 ? ('0' + B) : B;
		String G = Integer.toHexString(color.getGreen());
		G = G.length() < 2 ? ('0' + G) : G;
		return '#' + R + G + B;
	}

	protected static String readToken() {
		Scanner scanner = null;
		StringBuffer token = new StringBuffer();
		try {
			scanner = new Scanner(new File(TOKEN_STORE_PATH));
			while (scanner.hasNextLine()) {
				token.append(scanner.nextLine());
			}
		} catch (FileNotFoundException e) {
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
		return token.toString();
	}
}
